package com.itheima.hashset;

import java.util.HashSet;
import java.util.Iterator;

/*
HashSet 的基本使用
add
remove
removeIf
clear
isEmpty
size
contains

iterator
for
foreach
 */
public class Demo01 {

    public static void main(String[] args) {
        HashSet<String> set = new HashSet<>();
        set.add("abc");
        set.add("abc");
        set.add("abdef");
        set.add("jkl");
        set.add("xyz");
        set.add("ghi");
        set.add("def");
       /* System.out.println(set.size());
        set.remove("ghi");
        System.out.println(set);
        set.removeIf(x->x.startsWith("ab"));
        System.out.println(set);
        System.out.println(set.contains("xyz"));
        System.out.println(set.contains("abc"));
        set.clear();
        System.out.println(set);
        System.out.println(set.isEmpty());*/

        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("---------------");
        for (String s : set) {
            System.out.println(s);
        }
        System.out.println("---------------");
        set.forEach(a->
            System.out.println(a)
        );


    }
}
